<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <link rel="stylesheet" type="text/css" th:href="@{../static/css/edit.css}">
</head>
<body>
    <button id="back"><a th:href="@{/toIndex}">返回</a></button>
    <div id="editText">
        <form method="post" action="/update/updateRevexp" name="editForm">
            <input type="hidden" th:value="${revExp.getId()}" name="id" readonly>
            <p>添加者：</p><input type="text" th:value="${revExp.getAdder()}" name="adder" id="adder"><br/>
            <p>金&emsp;额：</p><input type="text" th:value="${revExp.getMoney()}" name="money"><br/>
            <p>类&emsp;型：</p><input type="text" th:value="${revExp.getType()}" name="type"><br/>
            <p>日&emsp;期：</p><input type="text" th:value="${revExp.getDate()}" name="date"><br/>
            <p>描&emsp;述：</p><input type="text" th:value="${revExp.getDescribes()}" name="describes"><br/>
            <div th:if="${session.auth}==0">
                <p>删&emsp;除：</p>
                <input type="text" th:value="${revExp.getDeleted()}" name="deleted"><br/>
            </div>
            <input type="button" value="修改" class="modBtn" onclick="sub()">
        </form>
    </div>

<script th:inline="javascript">
    window.onload = function() {
        var auth = [[${session.auth}]];
        if(auth!=0){
            document.getElementById("adder").setAttribute("readOnly",true);
        }
    }

    function sub(){
        //验证标记
        var flag = 0;

        var money_res = document.getElementsByName("money")[0].value.match(/\d+.?\d*/g);
        if (money_res!=null) {
            if (money_res.length === 1 && money_res[0] != "") flag++;
            else alert("金额数值有误！");
        }else alert("金额数值有误！");

        var type = document.getElementsByName("type")[0].value;
        if (type==="0" || type==="1") flag++;
        else alert("类型有误！");

        var date = document.getElementsByName("date")[0].value.match(/\d{4}\-\d{2}\-\d{2}/g);
        if (date!=null){
            if (date.length === 1 && date[0] != "") flag++;
            else alert("日期格式错误！");
        }else alert("日期格式错误！");

        //数据都对就submit
        if (flag===3) document.editForm.submit();
    }
</script>
</body>
</html>